package openadmin.widgets.swing;

import java.text.ParseException;
import javax.swing.JFormattedTextField;

/**
 * TemplateJFormatTxt01 extends JFormattedTextField 
 * adding support for formatting arbitrary values
 * @version  0.1
 * Created 10-05-2009
 * Author Alfred Oliver
 */
public class TemplateJFormatTxt01 extends JFormattedTextField {

	/**	  	
	  * Constructs a new TemplateJFormatTxt01 with the specifies of size, visible and editable. 
	  * @param pSize. Sets the maximum size to the specified value.
	  * @param pVisible. If object is visible.  
	  * @param pEditable. If object is editable.  	 	  	 	    	 	  
	  */
	public TemplateJFormatTxt01(int pSize, boolean pVisible, boolean pEditable){
				
		this.setBackground(new java.awt.Color(228, 226, 226));
		this.setVisible(pVisible);
		this.setEditable(pEditable);		
		
		try {
		
			this.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter(format(pSize))));
		
		} catch (ParseException e) {
			
			e.printStackTrace();
		}
	}
	
	/**	  	
	  * Make the size value. 
	  * @param pSize. Sets the maximum size to the specified value.	  	  	 	    	 	  
	  */
	private String format(int pSize){
		
		String size = "";
		int i = 0;
		
		for (i=0; i < pSize; i++){
			
			size = size + "*";
		}
		
		return size;
	}
}
